package com.kaiwukj.android.ufamily.mvp.ui.page.order.mine;

import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.flyco.tablayout.SlidingTabLayout;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.kaiwukj.android.ufamily.R;
import com.kaiwukj.android.ufamily.app.base.review.BaseActivity;
import com.kaiwukj.android.ufamily.app.constant.ARouterUrlKt;
import com.kaiwukj.android.ufamily.mvp.http.entity.event.OrderEvent;
import com.kaiwukj.android.ufamily.mvp.http.entity.helper.TabEntity;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.OnClick;

@Route(path = ARouterUrlKt.OrderListUrl)
public class MyOrderActivity extends BaseActivity {
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tab)
    SlidingTabLayout tabLayout;
    @BindView(R.id.fl_content)
    ViewPager vpContent;


    private ArrayList<Fragment> fragments;


    @OnClick(R.id.container_left)
    void onBackClick() {
        onBackPressedSupport();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_evaluate;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        tvTitle.setText("我的订单");
        ArrayList<CustomTabEntity> tabEntities = new ArrayList<>();
        tabEntities.add(new TabEntity("全部"));
        tabEntities.add(new TabEntity("待付款"));
        tabEntities.add(new TabEntity("待服务"));
        tabEntities.add(new TabEntity("已完成"));

        String[] titles = {"全部", "待付款", "待服务", "已完成"};

        fragments = new ArrayList<>();
        fragments.add(MyOrderFragment.newInstance(-1));
        fragments.add(MyOrderFragment.newInstance(0));
        fragments.add(MyOrderFragment.newInstance(1));
        fragments.add(MyOrderFragment.newInstance(4));


        //tabLayout.setTabData(tabEntities, this, R.id.fl_content, fragments);
        tabLayout.setViewPager(vpContent, titles, this, fragments);
        tabLayout.setCurrentTab(0);

    }

    @Override
    protected void initData(Bundle savedInstanceState) {

    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onOrderEvent(OrderEvent event) {
        ((MyOrderFragment) fragments.get(tabLayout.getCurrentTab())).onOrderEvent(event);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        fragments.get(tabLayout.getCurrentTab()).onActivityResult(requestCode, resultCode, data);
    }
}
